﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System.Text.RegularExpressions;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;

namespace DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects
{
    public class SiteSettingsPage : WatiNBase
    {
        #region Constructors

        public SiteSettingsPage(WatiNBase watinBase) : base(watinBase.IEInstance, watinBase.SiteUrl, watinBase.DBName) { }

        public SiteSettingsPage(IE ieInstance, string siteUrl, string dbName) : base(ieInstance, siteUrl, dbName) { }

        #endregion

        #region Public Properties

        #region Span
        public Span PageTitle 
        { 
            get { return IEInstance.Span(Find.ById(s => s.EndsWith("dnnTITLE_titleLabel"))); } 
        }
        public Span SSLSettingsSpan
        {
            get { return IEInstance.Span(Find.ByText("SSL Settings")); }
        }
        public Span SiteBackgroundSettingsSpan
        {
            get { return IEInstance.Span(Find.ById(s => s.EndsWith("SiteSettings_ctlBackground"))); }
        }
        public Span SiteLogoSettingsSpan
        {
            get { return IEInstance.Span(Find.ById(s => s.EndsWith("SiteSettings_ctlLogo"))); }
        }
        #endregion

        #region Tables
        public Table SSLTable
        {
            get { return IEInstance.Table(Find.ById(s => s.EndsWith("SiteSettings_tblSSL"))); } 
        }
        public Table HostSettingsTable
        { 
            get { return IEInstance.Table(Find.ById(s => s.EndsWith("SiteSettings_tblHost"))); } 
        }
        public Table AdvancedSettingsTable
        {
            get { return IEInstance.Table(Find.ById(s => s.EndsWith("SiteSettings_tblAdvanced"))); }
        }
        public Table AppearanceTable
        {
            get { return IEInstance.Table(Find.ById(s => s.EndsWith("SiteSettings_tblAppearance"))); }
        }
        public Table PortalAliasTable
        {
            get { return IEInstance.Table(Find.ById(s => s.EndsWith("SiteSettings_portalAliases_dgPortalAlias"))); }
        }
        public Table UsabilityTable
        {
            get { return IEInstance.Table(Find.ById(s => s.EndsWith("SiteSettings_tblUsability"))); }
        }
        public Table ControlPanelModeTable
        {
            get { return IEInstance.Table(Find.ById(s => s.EndsWith("SiteSettings_optControlPanelMode"))); }
        }
        #endregion

        #region Links
        public Link HostSettingsLink
        {
            get { return SiteSettingsDiv.Link(Find.ByText(s => s.Contains("Host Settings"))); }
        }
        public Link AddNewAliasLink 
        { 
            get { return IEInstance.Link(Find.ByTitle("Add New Alias")); } 
        }
        public Link UpdateLink
        {
            get { return SiteSettingsDiv.Link(Find.ByTitle("Update")); }
        }
        public Link FrenchUpdateLink
        {
            get { return IEInstance.Link(Find.ByTitle(" Mettre à jour ")); }
        }
        public Link OldUpdateLink
        {
            get { return IEInstance.Link(Find.ByText("Update")); }
        }
        public Link GoToPaymentProcessorLink
        {
            get { return IEInstance.Link(Find.ByText(s => s.Contains("Go To Payment Processor WebSite"))); }
        }
        public Link AddModuleLink
        {
            get { return SiteSettingsDiv.Link(Find.ByTitle("Add Module")); }
        }
        public Link RemoveModuleLink
        {
            get { return IEInstance.Link(Find.ByTitle("Remove Module")); }
        }
        public Link AdvancedSettingsTab
        {
            get { return IEInstance.Link(Find.ByText("Advanced Settings")); }
        }
        public Link PortalAliasesSectionLink
        {
            get { return IEInstance.Link(Find.ByText(s => s.Contains("Portal Aliases"))); }
        }
        public Link SSLSectionLink
        {
            get { return IEInstance.Link(Find.ByText("SSL Settings")); }
        }
        public Link HostSectionLink
        {
            get { return ContentPane.Link(Find.ByText("Host Settings")); }
        }
        public Link SecuritySectionLink
        {
            get { return ContentPane.Link(Find.ByText("Security Settings")); }
        }
        public Link AppearanceSectionLink
        {
            get { return IEInstance.Link(Find.ByText("Appearance")); }
        }
        public Link UsabillitySectionLink
        {
            get { return IEInstance.Link(Find.ByText(s => s.Contains("Usability Settings"))); }
        }
        public Link PaymentSettingsSectionLink
        {
            get { return IEInstance.Link(Find.ByText(s => s.Contains("Payment Settings"))); }
        }
        public Link UploadBackgroundImgLink
        {
            get { return SiteBackgroundSettingsSpan.Link(Find.ByText(s => s.Contains("Upload File"))); }
        }
        public Link UploadLogoImgLink
        {
            get { return SiteLogoSettingsSpan.Link(Find.ByText(s => s.Contains("Upload File"))); }
        }
        public Link SaveFileBackgroundLink
        {
            get { return SiteBackgroundSettingsSpan.Link(Find.ByText(s => s.Contains("Save File"))); }
        }
        public Link SaveFileLogoLink
        {
            get { return SiteLogoSettingsSpan.Link(Find.ByText(s => s.Contains("Save File"))); }
        }
        #endregion

        #region TextFields
        public TextField AliasTextBox
        { 
            get { return IEInstance.TextField(Find.ById(new Regex(@".*SiteSettings_portalAliases_dgPortalAlias_ctl\d\d_txtHTTPAlias"))); }
        }
        public TextField PageQuotaField
        {
            get { return IEInstance.TextField(Find.ById(s => s.EndsWith("SiteSettings_txtPageQuota"))); }
        }
        public TextField UserQuotaField
        {
            get { return IEInstance.TextField(Find.ById(s => s.EndsWith("SiteSettings_txtUserQuota"))); }
        }
        public TextField SiteTitleField
        {
            get { return IEInstance.TextField(Find.ById(s => s.EndsWith("SiteSettings_txtPortalName"))); }
        }
        public TextField DescriptionField
        {
            get { return IEInstance.TextField(Find.ById(s => s.EndsWith("SiteSettings_txtDescription"))); }
        }
        public TextField KeywordsField
        {
            get { return IEInstance.TextField(Find.ById(s => s.EndsWith("SiteSettings_txtKeyWords"))); }
        }
        public TextField CopyrightField
        {
            get { return IEInstance.TextField(Find.ById(s => s.EndsWith("SiteSettings_txtFooterText"))); }
        }
        public TextField ProcessorUserIdField
        {
            get { return IEInstance.TextField(Find.ById(s => s.EndsWith("SiteSettings_txtUserId"))); }
        }
        public TextField ProcessorPasswordField
        {
            get { return IEInstance.TextField(Find.ById(s => s.EndsWith("SiteSettings_txtPassword"))); }
        }
        public TextField SiteLogHistoryField
        {
            get { return IEInstance.TextField(Find.ById(s => s.EndsWith("SiteSettings_txtSiteLogHistory"))); }
        }
        #endregion

        #region Images
        public Image PortalAliasSaveButtonPortal 
        {
            get { return IEInstance.Image(Find.ById(new Regex(@".*SiteSettings_portalAliases_dgPortalAlias_ctl\d\d_lnkSave"))); }
        }
       // public Image PortalAliasSaveButtonPortal2
        //{
          //  get { return IEInstance.Table(Find.ById(s => s.EndsWith("SiteSettings_portalAliases_dgPortalAlias"))).TableRows[3].TableCells[3].Image(Find.Any); }
        //}
        public Image PortalAliasesExpandButton
        {
            get { return IEInstance.Image(Find.ById(s => s.EndsWith("SiteSettings_dshAliases_imgIcon"))); }
        }
        public Image AppearanceExpandButton
        {
            get { return IEInstance.Image(Find.ById(s => s.EndsWith("SiteSettings_dshAppearance_imgIcon"))); }
        }
        public Image AdvancedSettingsButton
        {
            get { return IEInstance.Image(Find.ById(s => s.EndsWith("SiteSettings_dshAdvanced_imgIcon"))); }
        }
        public Image OtherSettingsExpandImage
        {
            get { return IEInstance.Image(Find.ById(s => s.EndsWith("SiteSettings_dshOther_imgIcon"))); }
        }
        public Image HostSettingsExpandButton
        {
            get { return IEInstance.Image(Find.ById(s => s.EndsWith("SiteSettings_dshHost_imgIcon"))); }
        }
        public Image UsabilitySettingsExpandButton
        {
            get { return IEInstance.Image(Find.ById(s => s.EndsWith("SiteSettings_dshUsability_imgIcon"))); }
        }
        public Image PaymentOptionsExpandButton
        {
            get { return IEInstance.Image(Find.ById(s => s.EndsWith("SiteSettings_dshPayment_imgIcon"))); }
        }
        #endregion

        #region SelectLists
        public SelectList DefaultLocaleSelectList
        {
            get { return IEInstance.SelectList(Find.ById(s => s.EndsWith("SiteSettings_cboDefaultLanguage"))); }
        }
        public SelectList PortalSkinSelectList
        {
            get { return AppearanceTable.SelectList(Find.ById(s => s.EndsWith("SiteSettings_ctlPortalSkin_cboSkin"))); }
        }
        public SelectList PortalContainerSelectList
        {
            get { return AppearanceTable.SelectList(Find.ById(s => s.EndsWith("SiteSettings_ctlPortalContainer_cboSkin"))); }
        }
        public SelectList EditSkinSelectList
        {
            get { return IEInstance.SelectList(Find.ById(s => s.EndsWith("SiteSettings_editSkinCombo"))); }
        }
        public SelectList EditContainerSelectList
        {
            get { return IEInstance.SelectList(Find.ById(s => s.EndsWith("SiteSettings_editContainerCombo"))); }
        }
        public SelectList BodyBackgroundSelectList
        {
            get { return IEInstance.SelectList(Find.ById(s => s.EndsWith("SiteSettings_ctlBackground_File"))); }
        }
        public SelectList LogoSelectList
        {
            get { return IEInstance.SelectList(Find.ById(s => s.EndsWith("SiteSettings_ctlLogo_File"))); }
        }
        public SelectList LoginPageSelectList
        {
            get { return IEInstance.SelectList(Find.ById(s => s.EndsWith("SiteSettings_cboLoginTabId"))); }
        }
        public SelectList UserProfilePageSelectList
        {
            get { return IEInstance.SelectList(Find.ById(s => s.EndsWith("SiteSettings_cboUserTabId"))); }
        }
        public SelectList SplashPageSelectList
        {
            get { return IEInstance.SelectList(Find.ById(s => s.EndsWith("SiteSettings_cboSplashTabId"))); }
        }
        public SelectList HomePageSelectList
        {
            get { return IEInstance.SelectList(Find.ById(s => s.EndsWith("SiteSettings_cboHomeTabId"))); }
        }
        public SelectList PaymentProcessorSelectList
        {
            get { return IEInstance.SelectList(Find.ById(s => s.EndsWith("SiteSettings_processorCombo"))); }
        }
        public SelectList CurrencySelectList
        {
            get { return IEInstance.SelectList(Find.ById(s => s.EndsWith("SiteSettings_currencyCombo"))); }
        }
        public SelectList AvailablePremiumModulesSelectList
        {
            get { return IEInstance.SelectList(Find.ByName(s => s.EndsWith("SiteSettings$ctlDesktopModules_Available"))); }
        }
        public SelectList SelectedPremiumModuleSelectList
        {
            get { return IEInstance.SelectList(Find.ByName(s => s.EndsWith("SiteSettings$ctlDesktopModules_Selected"))); }
        }
        public SelectList TimeZoneSelectList
        {
            get { return IEInstance.SelectList(Find.ById(s => s.EndsWith("SiteSettings_cboTimeZone"))); }
        }
        #endregion

        #region RadioButton
        public RadioButton PortalSkinSiteOption
        {
            get { return IEInstance.RadioButton(Find.ById(s => s.EndsWith("SiteSettings_ctlPortalSkin_optSite"))); }
        }
        public RadioButton PortalContainerSiteOption
        {
            get { return IEInstance.RadioButton(Find.ById(s => s.EndsWith("SiteSettings_ctlPortalContainer_optSite"))); }
        }
        public RadioButton EditSkinSiteOption
        {
            get { return IEInstance.RadioButton(Find.ById(s => s.EndsWith("SiteSettings_ctlAdminSkin_optSite"))); }
        }
        public RadioButton EditContainerSiteOption
        {
            get { return IEInstance.RadioButton(Find.ById(s => s.EndsWith("SiteSettings_ctlAdminContainer_optSite"))); }
        }
        public RadioButton NoneRegistrationRadioButton
        {
            get { return IEInstance.RadioButton(Find.ById(s => s.EndsWith("SiteSettings_optUserRegistration_0"))); }
        }
        public RadioButton PrivateRegistrationRadioButton
        {
            get { return IEInstance.RadioButton(Find.ById(s => s.EndsWith("optUserRegistration_1"))); }
        }
        public RadioButton PublicRegistrationRadioButton
        {
            get { return IEInstance.RadioButton(Find.ById(s => s.EndsWith("SiteSettings_optUserRegistration_2"))); }
        }
        public RadioButton VerifiedRegistrationRadioButton
        {
            get { return IEInstance.RadioButton(Find.ById(s => s.EndsWith("SiteSettings_optUserRegistration_3"))); }
        }
        public RadioButton PageEditorsControlPanelRadioButton
        {
            get { return IEInstance.RadioButton(Find.ById(s => s.EndsWith("SiteSettings_optControlPanelSecurity_0"))); }
        }
        public RadioButton SelectViewModeRadioButton
        {
            get { return ControlPanelModeTable.RadioButton(Find.ByValue("VIEW")); }
        }
        public RadioButton SelectEditModeRadioButton
        {
            get { return ControlPanelModeTable.RadioButton(Find.ByValue("EDIT")); }
        }
        public RadioButton SelectControlPanelMinimised
        {
            get { return UsabilityTable.RadioButton(Find.ByValue("MIN")); }
        }
        public RadioButton SelectControlPanelMaximised
        {
            get { return UsabilityTable.RadioButton(Find.ByValue("MAX")); }
        }

        #endregion

        #region CheckBoxes
        public CheckBox EnableInlineEditorCheckBox
        {
            get { return IEInstance.CheckBox(Find.ById(s => s.EndsWith("SiteSettings_chkInlineEditor"))); }
        }
        public CheckBox CreateChildFolderForNewAliasCheckBox
        {
            get
            {
                return PortalAliasTable.CheckBox(Find.ById(new Regex(@"dnn_ctr\d\d\d_SiteSettings_portalAliases_dgPortalAlias_ctl\d\d_chkChild")));
            }
        }
        #endregion

        #region FileUploads
        public FileUpload BackgroundImageFileUpload
        {
            get { return SiteBackgroundSettingsSpan.FileUpload(Find.ByName(s => s.Contains("$SiteSettings$ctlBackground$"))); }
        }
        public FileUpload LogoImageFileUpload
        {
            get { return SiteLogoSettingsSpan.FileUpload(Find.Any); }
        }
        #endregion

        #region Divs
        public Div SiteSettingsDiv
        {
            get { return IEInstance.Div(Find.ById("dnnSiteSettings")); }
        }
        #endregion

        #endregion

        #region Public Methods

        public Image GetPortalDeleteImage(int portalNumber)
        {
            //Returns the Delete image for the portal specified
            return PortalAliasTable.TableRows[portalNumber].Images[1];
        }

        public Image GetPortalEditButton(int portalNumber)
        {
            //Returns the Edit image for the portal specified
            return PortalAliasTable.TableRows[portalNumber].Image(Find.ByTitle("Edit"));
        }


        #endregion
    }
}
